﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ServiceProcess;

namespace Wicresoft.Task.Scheduler
{
    public partial class SchedulerService : ServiceBase
    {
        private IEnumerable<Task> tasklist;

        public SchedulerService()
        {
            InitializeComponent();

            tasklist = SchedulerHelper.GetAllTasks().ToArray();
        }

        protected override void OnStart(string[] args)
        {
            System.Threading.Tasks.Parallel.ForEach(tasklist, t =>
            {
                t.OnStart();
            });
        }

        protected override void OnStop()
        {
            System.Threading.Tasks.Parallel.ForEach(tasklist, t =>
            {
                t.OnStop();
            });
        }
    }
}
